package view.toolbar.alert
{
	import config.Lang;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import model.Application;
	
	import util.Button;
	import util.ButtonType;
	import util.Container;
	
	import view.room.Room;
	import view.toolbar.Dice;

	public class AlertPlayerResult extends SuperAlert
	{
		private var _ui:UIAlertPlayerResult;
		
		public var btnsContainer:Container;
		
		public function AlertPlayerResult()
		{
			super();
			createUI();
		}
		
		private function createUI():void
		{
			_ui = new UIAlertPlayerResult;
			addChild(_ui);
			addBtns(_ui.btnsContainer);
		}
		
		private function addBtns(btnsContainer:Container):void
		{
			var btnBelieve:Button = new Button(ButtonType.YES, Lang.Believe);
			var btnNotBelieve:Button = new Button(ButtonType.NO, Lang.NotBelieve);
			
			btnBelieve.addEventListener(MouseEvent.CLICK, onClick);
			btnNotBelieve.addEventListener(MouseEvent.CLICK, onClick);
			
			btnsContainer.addItem(btnBelieve);
			btnsContainer.addItem(btnNotBelieve);
			
			function onClick(e:MouseEvent):void
			{
				if((e.target as Button).type == 1){
					Application.instance().open();
				}
				else{
					Room.instance().showBoastWin();
				}
			}
		}
		
		public function setCurrentDice(value:Object):void{
			for(var element:String in value){
				_ui.numTxt.text = value[element];
				removeContainer();
				addDice(int(element));
			}
		}
		
		private function addDice(value:int):void
		{
			var dice:Dice = new Dice;
			dice.setPoint(value);
			_ui.diceContainer.addChild(dice);
		}
		
		private function removeContainer():void{
			while( _ui.diceContainer.numChildren>0){
				_ui.diceContainer.removeChildAt(0);
			}
		}
	}
}